package net.zdreamer.geracomium.ui.home;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;

import com.example.geracomium.R;

import net.zdreamer.geracomium.adapter.GeracomiumYNSS_ZBHJ_FWZNAdapter;
import net.zdreamer.geracomium.entity.GeracomiumInfosYNSS_ZBHJ_FWZN;
import net.zdreamer.geracomium.ui.BaseActivity;

public class GeracomiunInfosActivity extends BaseActivity implements OnClickListener{
	private ListView listView;
	private GeracomiumYNSS_ZBHJ_FWZNAdapter mAdapter;
	private TextView title;
	private static int WITCH;
	private ImageView back, comment, share, assess;
	private SelectPicPopupWindow pop;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initSize();
	}

	@Override
	protected int getContentView() {
		return R.layout.activity_geracomium_all_details;
	}

	@Override
	protected void init() {
		Intent intent = getIntent();
		WITCH = Integer.valueOf(intent.getStringExtra("witch"));
		listView = (ListView) findViewById(R.id.list_geracomium_infos_all);
		title = (TextView) findViewById(R.id.title_content);
		back = (ImageView) findViewById(R.id.back);
		comment = (ImageView) findViewById(R.id.bottom_comment);
		share = (ImageView) findViewById(R.id.bottom_share);
		assess = (ImageView) findViewById(R.id.bottom_assess);
	}

	@Override
	protected void initViews() {
		GeracomiumInfosYNSS_ZBHJ_FWZN ss = new GeracomiumInfosYNSS_ZBHJ_FWZN();
		mAdapter = new GeracomiumYNSS_ZBHJ_FWZNAdapter(this, ss.items,
				R.layout.list_geracomium_info);
		listView.setAdapter(mAdapter);
		switch (WITCH) {
		case 1:
			title.setText("院内设施");
			break;
		case 2:
			title.setText("周边环境");
			(findViewById(R.id.detail_bottom)).setVisibility(View.GONE);
			break;
		case 3:
			title.setText("服务指南");
			break;

		default:
			break;
		}
	}

	@Override
	protected void initListener() {
		back.setOnClickListener(this);
		comment.setOnClickListener(this);
		share.setOnClickListener(this);
		assess.setOnClickListener(this);
	}

	private void initSize() {
		LinearLayout layout = (LinearLayout) findViewById(R.id.detail_bottom);
		LayoutParams aa = (LayoutParams) layout.getLayoutParams();
		LinearLayout.LayoutParams layoutParams = (LayoutParams) findViewById(
				R.id.bottom_share).getLayoutParams();
		LinearLayout.LayoutParams bb = (LayoutParams) findViewById(
				R.id.ssssssline).getLayoutParams();
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		int screenWidth = dm.widthPixels;
		layoutParams.height = screenWidth * 100 / 260 / 3;
		aa.height = layoutParams.height;
		bb.height = screenWidth * 60 / 260 / 3;
		layout.setLayoutParams(aa);
		findViewById(R.id.ssssssline).setLayoutParams(bb);
		findViewById(R.id.ssssssline1).setLayoutParams(bb);
		findViewById(R.id.bottom_share).setLayoutParams(layoutParams);
		findViewById(R.id.bottom_assess).setLayoutParams(layoutParams);
		findViewById(R.id.bottom_comment).setLayoutParams(layoutParams);
	}
	private void showPop() {
		pop = new SelectPicPopupWindow(this);
		pop.setAnimationStyle(R.style.popwin_anim_style);
		// 引入窗口配置文件
		View view = View.inflate(this, R.layout.popwindow_shara,
				null);
		view.findViewById(R.id.share_sina).setOnClickListener(pop_click);
		view.findViewById(R.id.share_tencent).setOnClickListener(pop_click);
		view.findViewById(R.id.share_wechat).setOnClickListener(pop_click);
		view.findViewById(R.id.pop_undo).setOnClickListener(pop_click);
		pop.init(view).showAtLocation(findViewById(R.id.bg_pop2),
				Gravity.CENTER, 0, 0);
	}

	public class SelectPicPopupWindow extends PopupWindow {

		public SelectPicPopupWindow(Activity context) {
			super(context);
		}

		public SelectPicPopupWindow init(View view) {
			this.setContentView(view);
			this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
			this.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
			this.setBackgroundDrawable(new ColorDrawable(0xb0000000));
			setFocusable(true);
			return this;
		}

	}

	OnClickListener pop_click = new OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.share_sina:
				
				break;

			case R.id.share_tencent:
				
				break;

			case R.id.share_wechat:
				
				break;

			case R.id.pop_undo:
				pop.dismiss();
				break;

			default:
				break;
			}
		}

	};
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;
		case R.id.bottom_comment:
			// 跳转评论界面
			startActivity(new Intent(this, CommentActivity.class));
			break;
		case R.id.bottom_share:
			// 弹出分享窗口
			showPop();
			// mController.openShare(getActivity(), false);
			break;
		case R.id.bottom_assess:
			// 跳转评估界面
			startActivity(new Intent(this, AssessActivity.class));
			break;
		default:
			break;
		}
	}

}
